﻿#pragma once
#include "Models_scene.h"
#include "Render.h"
#include "Camera.h"
#include "Animate.h"
#include "SkeletonAnimation.h"
#include "FboColorPick.h"

class Terrain;

#pragma pack(push,1)
struct TerrainObjInfo
{
	short index;
	float position[3];
	float rotate[3];
	float scale;
};
#pragma pack(pop)

struct DrawObjInfo
{
	int index;
	//Render *render;
	//Animate *animate;
	glm::mat4 trans;
	float color[4];
};

class RenderSceneModels
{
public:
	class PoseBoundBox : public BoundBoxObject
	{
	public:
		PoseBoundBox()
		{
			m_objType = ot_poseBox;
            position = glm::ivec2(0);
            trans = nullptr;
		}
		glm::ivec2 position;
		glm::mat4 *trans;
	};

	RenderSceneModels();
	~RenderSceneModels();

	void Init(Camera *camera, Shader *shader, Terrain *terrain);
	//index 地图编号, 0=勇者大陆(Object1目录), 1=地下城(Object2), 2=冰风谷(Object3), 3=仙踪林(Object4)
	void Load(int index);
	//drawArea: 位置和宽高
	void UpdateArea(glm::ivec4 &drawArea);
	void Draw();
	void Clear();
	virtual void OnFocus(bool focus);
	virtual void OnSelect(bool select);
	BoundBoxObject *GetBoundBox(int index);
	int GetBoundBoxCount();
	//std::vector<RenderObject*> m_boundBoxObjs;

private:
	bool ReadTerrainObj(char *fileName);

	
	Camera *m_camera;
	Shader *m_shader;
	Terrain *m_terrain;
	Models_scene m_mdls_load;
	//Render	*m_renders;
	//Animate *m_animate;
	std::vector<PoseBoundBox> m_boundBoxObjs;
	std::vector<SkeletonAnimation *> m_skelAnimObjs;
	std::vector<DrawObjInfo> m_drawInfos[256][256];
	glm::ivec4 m_drawArea;	//drawArea: 位置和宽高
	std::vector<std::vector<DrawObjInfo*>> m_drawList;
};

